package com.example.demo.api;

import com.example.demo.domain.Teacher;
import com.example.demo.service.TeacherService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.persistence.Entity;
import java.util.List;

/**
 * @program: demo
 * @description:
 * @author: 陈程猿
 * @create: 2024-11-27 09:13
 **/

@RestController
@RequestMapping("/api/teacher")
public class TeacherApiController {

    @Resource
    private TeacherService teacherService;


    /**
     * 查询所有教师
     * @return
     */
    @GetMapping("/list")
    public List<Teacher> getAllTeacher(){
        List<Teacher> teacherList = this.teacherService.findAllTeacher();
        return teacherList;
    }

    /**
     * 根据教师姓名查询
     * @param teacherName
     * @return
     */
    @RequestMapping("/search")
    public List<Teacher> search(String teacherName){
        List<Teacher> teacherList = this.teacherService.findByNameLike("%"+teacherName+"%");
        return teacherList;
    }

    /**
     * 保存学生信息
     * @param teacher
     */
    @PostMapping("/saveInfo")
    public void saveInfo(Teacher teacher){
         this.teacherService.saveInfo(teacher);
    }

    /**
     * 删除信息
     * @param teacher
     */
    @RequestMapping("/delData")
    public void delData(Teacher teacher){
        this.teacherService.deleteTeacher(teacher);
    }
}
